<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="分管单位">
              <a-input placeholder="请输入所属院" v-model="queryParam.company"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="选择风险级别">
              <j-dict-select-tag v-model="queryParam.riskLevel" placeholder="请选择风险级别" dictCode="	risk" />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="选择施工进度">
              <j-dict-select-tag v-model="queryParam.riskLevel" placeholder="请选择施工进度" dictCode="	risk" />
            </a-form-item>
          </a-col> -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编码">
              <a-input placeholder="请输入项目编码" v-model="queryParam.projectCode"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <!-- <template > -->
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目类别">
                <a-input placeholder="请输入项目类别" v-model="queryParam.projectType"></a-input>
              </a-form-item>
            </a-col> -->

          <!-- </template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
      <!-- 以下为原有的 -->
      <!-- <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编码">
              <a-input placeholder="请输入项目编码" v-model="queryParam.projectCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目类别">
                <a-input placeholder="请输入项目类别" v-model="queryParam.projectType"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="风险级别">
                <a-input placeholder="请输入风险级别" v-model="queryParam.riskLevel"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="选择分管单位">
                <a-input placeholder="请输入所属院" v-model="queryParam.company"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form> -->
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls('项目维护')">导出</a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <project-modal ref="modalForm" @ok="modalFormOk"></project-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ProjectModal from './modules/ProjectModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'

export default {
  name: 'ProjectList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ProjectModal,
    JSuperQuery,
  },
  data() {
    return {
      description: '项目维护管理页面',
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        {
          title: '项目编码',
          align: 'center',
          dataIndex: 'projectCode',
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '分管单位',
          align: 'center',
          dataIndex: 'company',
        },
        {
          title: '项目规模',
          align: 'center',
          dataIndex: 'projectScale',
        },
        {
          title: '项目类别',
          align: 'center',
          dataIndex: 'projectType',
        },
        {
          title: '风险级别',
          align: 'center',
          dataIndex: 'riskLevel',
        },
        // {
        //   title:'项目概况',
        //   align:"center",
        //   dataIndex: 'projectDesc'
        // },

        {
          title: '承担部门',
          align: 'center',
          dataIndex: 'projectDept',
        },
        {
          title: '项目经理',
          align: 'center',
          dataIndex: 'prinName',
        },
        // {
        //   title:'项目负责人电话',
        //   align:"center",
        //   dataIndex: 'prinTel'
        // },
        {
          title: '安全负责人',
          align: 'center',
          dataIndex: 'safeName',
        },
        {
          title: '项目地点',
          align: 'center',
          dataIndex: 'projectAddr',
        },
        {
          title: '施工进度',
          align: 'center',
          dataIndex: 'projectRate',
        },
        // {
        //   title:'经度',
        //   align:"center",
        //   dataIndex: 'longitude'
        // },
        // {
        //   title:'纬度',
        //   align:"center",
        //   dataIndex: 'latitude'
        // },
        // {
        //   title:'高程',
        //   align:"center",
        //   dataIndex: 'elevationi'
        // },
        // {
        //   title:'省',
        //   align:"center",
        //   dataIndex: 'projectProv'
        // },
        // {
        //   title:'市',
        //   align:"center",
        //   dataIndex: 'projectCity'
        // },
        // {
        //   title:'区县',
        //   align:"center",
        //   dataIndex: 'projectCounty'
        // },

        {
          title: '总人数',
          align: 'center',
          dataIndex: 'peopleNum',
        },
        // {
        //   title:'职工人数',
        //   align:"center",
        //   dataIndex: 'staffNum'
        // },
        {
          title: '第三方人数',
          align: 'center',
          dataIndex: 'thirdNum',
        },
        // {
        //   title:'钻机总数',
        //   align:"center",
        //   dataIndex: 'rigNum'
        // },
        // {
        //   title:'自有钻机数',
        //   align:"center",
        //   dataIndex: 'rigSelf'
        // },
        // {
        //   title:'应急装备（字符串，支持逗号分隔）',
        //   align:"center",
        //   dataIndex: 'emergency'
        // },
        {
          title: '开始时间',
          align: 'center',
          dataIndex: 'beginDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '结束时间',
          align: 'center',
          dataIndex: 'endDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },

        // {
        //   title:'项目图片地址',
        //   align:"center",
        //   dataIndex: 'avatar'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/business/project/list',
        delete: '/business/project/delete',
        deleteBatch: '/business/project/deleteBatch',
        exportXlsUrl: '/business/project/exportXls',
        importExcelUrl: 'business/project/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'projectCode', text: '项目编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectType', text: '项目类别', dictCode: 'project_type' })
      fieldList.push({ type: 'Text', value: 'projectDesc', text: '项目概况', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectScale', text: '项目规模', dictCode: 'project_scale' })
      fieldList.push({ type: 'string', value: 'projectDept', text: '承担部门', dictCode: '' })
      fieldList.push({ type: 'string', value: 'prinName', text: '项目负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'prinTel', text: '项目负责人电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'safeName', text: '安全负责人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'riskLevel', text: '风险级别', dictCode: 'risk' })
      fieldList.push({ type: 'double', value: 'longitude', text: '经度', dictCode: '' })
      fieldList.push({ type: 'double', value: 'latitude', text: '纬度', dictCode: '' })
      fieldList.push({ type: 'double', value: 'elevationi', text: '高程', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectProv', text: '省', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectCity', text: '市', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectCounty', text: '区县', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectAddr', text: '详细地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectRate', text: '项目进度', dictCode: '' })
      fieldList.push({ type: 'int', value: 'peopleNum', text: '总人数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'staffNum', text: '职工人数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'thirdNum', text: '第三方人数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'rigNum', text: '钻机总数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'rigSelf', text: '自有钻机数', dictCode: '' })
      fieldList.push({ type: 'string', value: 'emergency', text: '应急装备（字符串，支持逗号分隔）', dictCode: '' })
      fieldList.push({ type: 'date', value: 'beginDate', text: '开始时间' })
      fieldList.push({ type: 'date', value: 'endDate', text: '结束时间' })
      fieldList.push({ type: 'string', value: 'company', text: '所属院', dictCode: '' })
      fieldList.push({ type: 'string', value: 'avatar', text: '项目图片地址', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>